<?php
header("Pragma: public");
header("Expires: 0");
header("Accept-Ranges: bytes");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/vnd.ms-excel");
header('Content-Disposition: attachment; filename=listcommstudentsdata.xls');
header("Content-Transfer-Encoding: binary");
?>
<table width="100%" class="art-article">
  <tr>
    <th width="30%" scope="col">ФИО</th>
    <th width="30%" scope="col">Факультет</th>
    <th width="40%" scope="col">Данные договора </th>
  </tr>
<?php 
	foreach($students as $student):
?>  
  <tr>
    <td width="30%">
	<?php 
	echo $student['Studentinfo']['lastname'].' ';
	echo $student['Studentinfo']['firstname'].' ';
	echo $student['Studentinfo']['surname'];	
	?>
	</td>
    <td width="30%">
	<?php 
	foreach ($studentgroups as $studentgroup):
		if ($studentgroup['Studentgroup']['id'] == $student['Studentinfo']['Student']['studentgroup_id']){
			$course_id = $studentgroup['Studentgroup']['course_id'];
			$group_name = $studentgroup['Studentgroup']['name'];
			break;
		}
	endforeach;
	foreach ($courses as $course):
		if ($course['Course']['id'] == $course_id){
			$course_name = $course['Course']['name'];
			$profession_id = $course['Course']['profession_id'];
			break;
		}
	endforeach;
	foreach ($professions as $profession):
		if ($profession['Profession']['id'] == $profession_id){
			$profession_name = $profession['Profession']['name'];
			$facultet_id = $profession['Profession']['facultet_id'];
			break;
		}
	endforeach;
		echo 'факультет: '.$facultets[$facultet_id].', ';
		echo 'специальность: '.$profession_name.', ';
		echo 'курс: '.$course_name.', ';
		echo 'группа: '.$group_name;
	?>
	</td>
    <td width="40%">
	<?php 
	echo $student['Contract']['data'];
	?>
	</td>
  </tr>
  <?php 
  endforeach;
  ?>
</table>